package pers.xdrodger.simple;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import pers.xdrodger.simple.enums.FoodType;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class SimpleTest {

    private List<Food> getFoodList() {
        List<Food> result = new ArrayList<>();
        Random random = new Random();
        int length = random.nextInt( 10) + 10;
        for (int i = 0; i < length; i ++) {
            Food food = new Food();
            food.setId(UUID.randomUUID().toString());
            food.setName(RandomStringUtils.randomAlphabetic(5));
            if (i % 4 == 0) {
                food.setType(FoodType.Fruit);
            } else if (i % 4 == 1) {
                food.setType(FoodType.Vegetable);
            } else if (i % 4 == 2) {
                food.setType(FoodType.Meat);
            } else {
                food.setType(FoodType.Grain);
            }
            result.add(food);
        }
        return result;
    }

    @Test
    public void testFilter() {
        List<Food> result = getFoodList();
        System.out.println(JSON.toJSONString(result));

        List<Food>  fruitList = result.stream().filter(n -> n.getType().equals(FoodType.Fruit)).collect(Collectors.toList());
        System.out.println(JSON.toJSONString(fruitList));
    }

    @Test
    public void testString() {
        String str = "ABc";
        System.out.println(str.toLowerCase());
    }

    @Test
    public void testMap() {
        Map<String, String> map = new HashMap<>();
        map.put("1", null);
        map.put("2", "");
        System.out.println(JSON.toJSONString(map));
        System.out.println(map.get("1"));
    }

    @Test
    public void testExtractString() {
//        String rawString = "<p>测试<span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">4554{{</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">我</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">:</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">我</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">,</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">你</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">,</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">他</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">}}52323{{</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">你</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">:</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">我</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">,</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">你</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">,</span><span style=\\\"font-size: 13.5pt; color: #6a8759; font-family: 宋体;\\\">他</span><span style=\\\"font-family: 'JetBrains Mono'; font-size: 13.5pt; color: #6a8759;\\\">}}</span></p>";
//        String rawString = "哈哈哈{{我:我,你,他}}，哈哈{{我:我,你,他组织}}哈看看";
        String rawString = "<p>哈哈{{我:我,你,他}}，哈哈{{我:我,你,他组织}}哈看看</p>\",\"zh_CN\":\"<p>哈哈<em>{{我:我,你,他}}</em>，哈哈<strong>{{我:我,你,他组织}}</strong>哈看看</p>";
        String express = "\\{\\{(.*?)[\\|\\|.*?]?}}";
        System.out.println(express);
        Matcher match = Pattern.compile(express).matcher(rawString);
        while (match.find()) {
            System.out.println(match.group(1));
        }
        System.out.println();
    }

    @Test
    public void testExtractAndReplaceString() {
        StringBuffer sb = new StringBuffer() ;
        Pattern p = Pattern.compile("\\{\\{(.*?)[\\|\\|.*?]?}}") ;
        String rawString = "<p>哈哈{{我:我,你,他}}，哈哈{{我:我,你,他组织}}哈看看</p>\",\"zh_CN\":\"<p>哈哈<em>{{我:我,你,他}}</em>，哈哈<strong>{{我:我,你,他组织}}</strong>哈看看</p>";
        System.out.println(rawString);
        Matcher m = p.matcher(rawString) ;
        while( m.find() ){
            String tmp = m.group() ;
            System.out.println(tmp);
            String v = "要替换成字符串";
            String[] strArr =  tmp.split(":");
            v = v.replace("\\", "\\\\").replace("$", "\\$");
            //替换掉查找到的字符串
            m.appendReplacement(sb, strArr[0]);
        }
        //别忘了加上最后一点
        m.appendTail(sb) ;
        System.out.println(sb);
        String s = sb.toString();
        System.out.println(s.replaceAll("\\{", ""));

    }

    @Test
    public void testLoop() {
        for (int i =0; i < Integer.MAX_VALUE; i ++) {
//            System.out.println(i);
        }
    }

    @Test
    public void testParseDetailedScore() {
        String str = "{\"detailedScoreConfig\":[{\"name\":{\"zh_CN\":\"领导自我\"},\"isSelect\":true,\"detailedScoreChildDimensions\":[{\"code\":\"360-PY-KYNL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"抗压能力\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TZSY\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"调整适应\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-LHBT\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"灵活变通\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JJZD\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"积极主动\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JZJY\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"尽职敬业\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZXGG\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"自信果敢\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SJGL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"时间管理\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-XXCZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"学习成长\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-XTSW\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"系统思维\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZWRZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"自我认知\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-KFBR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"开放包容\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZQZY\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"追求专业\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CXZZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"诚信正直\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-QXGL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"情绪管理\"},\"type\":\"DIMENSION_AVERAGE\"}]},{\"name\":{\"en_US\":\"\",\"zh_CN\":\"领导他人\"},\"isSelect\":true,\"detailedScoreChildDimensions\":[{\"code\":\"360-PY-GXGT\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"高效沟通\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-RWWP\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"任务委派\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JLFD\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"教练辅导\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TDNJ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"团队凝聚\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SRYR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"识人用人\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TDJS\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"梯队建设\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JLRK\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"激励认可\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JLXR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"建立信任\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JYGX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"经营关系\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SQWZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"授权委责\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-DZRJWL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"打造人际网络\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-YXSF\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"影响说服\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-YJYL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"愿景引领\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-XTHZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"协同合作\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CTGL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"冲突管理\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CJHZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"促进合作\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-FZDYX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"发展多样性\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-PYTR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"培养他人\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TDGH\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"团队规划\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JXGL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"绩效管理\"},\"type\":\"DIMENSION_AVERAGE\"}]},{\"name\":{\"en_US\":\"\",\"zh_CN\":\"完成当前业务\"},\"isSelect\":true,\"detailedScoreChildDimensions\":[{\"code\":\"360-PY-JHAP\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"计划安排\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-FXBK\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"风险把控\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JCPD\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"决策判断\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-GHBS\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"规划部署\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SCDC\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"市场洞察\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZYGL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"资源管理\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-GZKH\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"关注客户\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-QBZX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"确保执行\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-YKHWZX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"以客户为中心\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JLGZGF\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"建立工作规范\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SJMR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"数据敏锐\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-WTJJ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"问题解决\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZQGZZL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"追求工作质量\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CWMR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"财务敏锐\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JGDX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"结果导向\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-QJYS\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"全局意识\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZZMR\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"组织敏锐\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-GXZX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"高效执行\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-GZSC\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"关注市场\"},\"type\":\"DIMENSION_AVERAGE\"}]},{\"name\":{\"en_US\":\"\",\"zh_CN\":\"关注未来业务\"},\"isSelect\":true,\"detailedScoreChildDimensions\":[{\"code\":\"360-PY-CXGS\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"持续改善\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CDZZWBJ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"倡导组织无边界\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TSZZNL\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"提升组织能力\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-DZXXXZZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"打造学习型组织\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-JYBQD\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"驾驭不确定\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-QQSY\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"全球视野\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-SYRZ\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"商业睿智\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-ZLSW\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"战略思维\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TDCX\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"推动创新\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-TDBG\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"推动变革\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-YLBG\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"引领变革\"},\"type\":\"DIMENSION_AVERAGE\"},{\"code\":\"360-PY-CXTP\",\"isSelected\":false,\"name\":{\"en_US\":\"\",\"zh_CN\":\"创新突破\"},\"type\":\"DIMENSION_AVERAGE\"}]}]}";
        JSONArray jsonArray = JSONArray.parseObject(str).getJSONArray("detailedScoreConfig");
        for (Object o : jsonArray) {
            JSONObject jsonObject = (JSONObject) o;
            JSONArray sonJsonArray = jsonObject.getJSONArray("detailedScoreChildDimensions");
            for (Object o2 : sonJsonArray) {
                JSONObject jsonObject2 = (JSONObject) o2;
                System.out.println(jsonObject2.getString("code"));
            }
        }
    }

    @Test
    public void testParseAdaptationDetailed() {
        String str = "";
        JSONArray jsonArray = JSONArray.parseObject(str).getJSONArray("adaptationDetailsConfig");
        for (Object o : jsonArray) {
            JSONObject jsonObject = (JSONObject) o;
            JSONArray sonJsonArray = jsonObject.getJSONArray("adaptationDetailsChildDimension");
            for (Object o2 : sonJsonArray) {
                JSONObject jsonObject2 = (JSONObject) o2;
                System.out.println("--" + jsonObject2.getString("weights"));
            }
        }
    }

    @Test
    public void test() {
        String text = "Sheet1!$B$2:$B$7";
        Pattern p = Pattern.compile("[\\d]");
        Matcher matcher = p.matcher(text);
        String result = matcher.replaceAll("");
        System.out.println(result);
        System.out.println(text.replace("\\d", ""));

    }

    @Test
    public void test2() {
        String text = "Sheet1!$B$2:$B$7";
        Pattern p = Pattern.compile("\\$[A-Z]\\$");
        Matcher matcher = p.matcher(text);
        System.out.println(matcher.toString());
        if (matcher.find()) {
            System.out.println(matcher.group());
        }
//        String result = matcher.replaceAll("");
//        System.out.println(result);

    }

    @Test
    public void testPrintSql() {
        Map<String, String> map = new HashMap<>();
        map.put("1", "11");
        map.put("2", "11");
        map.put("3", "112");
        map.put("4", "113");
        Map<String, String> newMap = map.entrySet().stream().filter(n -> n.getValue().equals("11")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        System.out.println(newMap.toString());
    }

    @Test
    public void testEmptyList() {
        List<String> list = new ArrayList<>();
        List<String> group = new ArrayList<>();
        group.addAll(list);
        System.out.println(group.size());

        List<String> list1 = new ArrayList<>(10);
        list1.add("1");
        list1.add(null);
        System.out.println(list1.get(0));
        System.out.println(list1.get(1));
//        System.out.println(list1.get(2));
        String[] str = new String[10];
        System.out.println("--");
    }

    @Test
    public void removeJson() {
        StringBuilder rawJson = new StringBuilder("");

        JSONObject jsonObject = JSONObject.parseObject(rawJson.toString());
        JSONArray assessmentInfos = jsonObject.getJSONArray("assessmentInfos");
        for (Object o : assessmentInfos) {
            JSONObject assessmentInfo = (JSONObject) o;
            JSONArray detailList = assessmentInfo.getJSONArray("detailList");
            for (Object o2 : detailList) {
                JSONObject detail = (JSONObject) o2;
                detail.remove("projectName");
                detail.remove("key");
                detail.remove("nairName");
                detail.remove("time");
                detail.remove("name");
            }
        }
        System.out.println(jsonObject.toJSONString());

    }

}
